import qs from 'qs'

export default $axios => ({
    signOn(username, phone, checkCode) {
        return $axios.get('/server/code', {
            params: {
                username,
                phone,
                checkCode
            }
        })
    },
    getWordList(word) {
        return $axios.post('/server/code', qs.stringify({
            word
        }))
    },
    
    getAccountByUsername(username) {
        return $axios.get('/server/account', {
            params: {
                type: 'getAccountByUsername',
                username
            }
        })
    },
    register(account) {
        return $axios.post('/server/account', qs.stringify(account))
    },
    getAccountByUsernameAndPassword(username, password) {
        return $axios.get('/server/account', {
            params: {
                type: 'getAccountByUsernameAndPassword',
                username,
                password
            }
        })
    },
    updateAccount(account) {
        console.log('update account', account)
        return $axios.put('/server/account', qs.stringify({
            type: 'updateAccount',
            ...account
        }))
    },
    logIn(username, password) {
        return $axios.get('/server/account', {
            params: {
                type: 'getAccountByUsernameAndPassword',
                username,
                password
            }
        })
    }
})